package cn.sq.scaffold.ffmpeg.config;

import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * User: SQ
 * Date: 2020/6/29
 * Time: 10:44
 * Description:
 */
public class StatusCode {


    /**
     * 成功 请求成功且正常
     */
    public static Integer SUCCESS = 0;


    /**
     * ================错误类型=========================
     */


    /**
     * 错误 请求错误（未知的）
     */
    public static Integer Error = 100;
    /**
     * 没有提供认证信息。请求的时候没有带上 Token 等。
     */
    public static Integer Error_TOKEN = 101;
    /**
     * 请求的资源不允许访问。就是说没有权限。
     */
    public static Integer ERROR_PERMISSION = 103;
    /**
     * 请求的内容不存在
     */
    public static Integer ERROR_NOT_EXIST = 104;
    /**
     * 类型不正确
     */
    public static Integer ERROR_TYPE = 115;
    /**
     * 参数不完整或者错误
     */
    public static Integer ERROR_PARAMETER = 116;

    /**
     * =================登录错误===================
     * /
     * <p>
     * /**
     * 账户错误未知的（账号或密码错误）或系统错误
     */
    public static Integer ERROR_LOGIN = 120;

    /**
     * 账户名错误
     */
    public static Integer ERROR_LOGIN_USERNAME = 121;
    /**
     * 账户密码错误
     */
    public static Integer ERROR_LOGIN_PASSWORD = 122;
    /**
     * 账户被禁用
     */
    public static Integer ERROR_LOGIN_FLAG = 123;


    /**
     * token 为空
     */
    public static Integer ERROR_TOKEN_NULL = 600;
    /**
     * token值错误
     */
    public static Integer ERROR_TOKEN_ERROR = 601;


    /**
     * 全局的错误集合
     */
    public static HashMap<Integer, ResponseBean>  CODERESPONSEBEAN = null;


    /**
     * ResponseBean对象
     */

    /**
     * 成功 请求成功且正常
     */
    public static ResponseBean R_SUCCESS = StatusCode.codeToResponseBean(SUCCESS);;


    /**
     * ================错误类型=========================
     */


    /**
     * 错误 请求错误（未知的）
     */
    public static ResponseBean R_Error = StatusCode.codeToResponseBean(Error);
    /**
     * 没有提供认证信息。请求的时候没有带上 Token 等。
     */
    public static ResponseBean R_Error_TOKEN = StatusCode.codeToResponseBean(Error_TOKEN);
    /**
     * 请求的资源不允许访问。就是说没有权限。
     */
    public static ResponseBean R_ERROR_PERMISSION = StatusCode.codeToResponseBean(ERROR_PERMISSION);
    /**
     * 请求的内容不存在
     */
    public static ResponseBean R_ERROR_NOT_EXIST = StatusCode.codeToResponseBean(ERROR_NOT_EXIST);
    /**
     * 类型不正确
     */
    public static ResponseBean R_ERROR_TYPE = StatusCode.codeToResponseBean(ERROR_TYPE);
    /**
     * 参数不完整或者错误
     */
    public static ResponseBean R_ERROR_PARAMETER = StatusCode.codeToResponseBean(ERROR_PARAMETER);

    /**
     * =================登录错误===================
     * /
     * <p>
     * /**
     * 账户错误未知的（账号或密码错误）或系统错误
     */
    public static ResponseBean R_ERROR_LOGIN = StatusCode.codeToResponseBean(ERROR_LOGIN);

    /**
     * 账户名错误
     */
    public static ResponseBean R_ERROR_LOGIN_USERNAME = StatusCode.codeToResponseBean(ERROR_LOGIN_USERNAME);
    /**
     * 账户密码错误
     */
    public static ResponseBean R_ERROR_LOGIN_PASSWORD = StatusCode.codeToResponseBean(ERROR_LOGIN_PASSWORD);
    /**
     * 账户被禁用
     */
    public static ResponseBean R_ERROR_LOGIN_FLAG = StatusCode.codeToResponseBean(ERROR_LOGIN_FLAG);


    /**
     * token 为空
     */
    public static ResponseBean R_ERROR_TOKEN_NULL = StatusCode.codeToResponseBean(ERROR_TOKEN_NULL);
    /**
     * token值错误
     */
    public static ResponseBean R_ERROR_TOKEN_ERROR = StatusCode.codeToResponseBean(ERROR_TOKEN_ERROR);



    /**
     *
     * @param code
     * @return 通过code码获取
     */
    public static ResponseBean codeToResponseBean(Integer code){
        if (CODERESPONSEBEAN==null){
            pushResponseBean();
        }
       return CODERESPONSEBEAN.get(code);
    }

    /**
     * 操作成功
     * @param o
     * @return
     */
    public static ResponseBean successResponseBean(Object o){
        if (o instanceof Boolean){
            if (!(Boolean)o){
                return R_Error;
            }
        }
        return new ResponseBean(SUCCESS,"操作成功",o);
    }
    public static ResponseBean successResponseBean(Object o,Object o2){
        if (o instanceof Boolean){
            if (!(Boolean)o){
                return R_Error;
            }
        }
        return new ResponseBean(SUCCESS,"操作成功",o2);
    }
    public static ResponseBean successResponseBean(){
        if (CODERESPONSEBEAN==null){
            pushResponseBean();
        }
        return CODERESPONSEBEAN.get(SUCCESS);
    }
    public static void pushResponseBean(){
        CODERESPONSEBEAN=new HashMap<Integer, ResponseBean>();
        CODERESPONSEBEAN.put(SUCCESS,new ResponseBean(SUCCESS,"成功",true));
        CODERESPONSEBEAN.put(Error,new ResponseBean(Error,"失败",false));
        CODERESPONSEBEAN.put(Error_TOKEN,new ResponseBean(Error_TOKEN,"没有提供认证信息",false));
        CODERESPONSEBEAN.put(ERROR_PERMISSION,new ResponseBean(ERROR_PERMISSION,"请求的资源不允许访问",false));
        CODERESPONSEBEAN.put(ERROR_NOT_EXIST,new ResponseBean(ERROR_NOT_EXIST,"请求的内容不存在",false));
        CODERESPONSEBEAN.put(ERROR_TYPE,new ResponseBean(ERROR_TYPE,"类型不正确",false));
        CODERESPONSEBEAN.put(ERROR_PARAMETER,new ResponseBean(ERROR_PARAMETER,"参数不完整或者错误",false));
        CODERESPONSEBEAN.put(ERROR_LOGIN,new ResponseBean(ERROR_LOGIN,"账号或密码错误",false));
        CODERESPONSEBEAN.put(ERROR_LOGIN_USERNAME,new ResponseBean(ERROR_LOGIN_USERNAME,"账户名错误",false));
        CODERESPONSEBEAN.put(ERROR_LOGIN_PASSWORD,new ResponseBean(ERROR_LOGIN_PASSWORD,"密码错误",false));
        CODERESPONSEBEAN.put(ERROR_LOGIN_FLAG,new ResponseBean(ERROR_LOGIN_FLAG,"账户被禁用",false));
        CODERESPONSEBEAN.put(ERROR_TOKEN_NULL,new ResponseBean(ERROR_TOKEN_NULL,"token 为空",false));
        CODERESPONSEBEAN.put(ERROR_TOKEN_ERROR,new ResponseBean(ERROR_TOKEN_ERROR,"密码错误",false));
        CODERESPONSEBEAN.put(ERROR_LOGIN_PASSWORD,new ResponseBean(ERROR_LOGIN_PASSWORD,"token值错误",false));
    }
}
